package com.cyandpos.pad.cateringformat.morefunction.model;

import android.text.TextUtils;
import android.util.Log;

import com.cyandpos.pad.common.commondata.BaseResponse;
import com.cyandpos.pad.common.netmanager.PosHttpManager;
import com.cyandpos.pad.http.OkHttpUtils;
import com.cyandpos.pad.posdata.TableReserveData;
import com.google.gson.JsonObject;

public class OrderFoodInfoModelImpl implements OrderFoodInfoModel {

    @Override
    public void loadOrderFoodInfo(int shopid, final OnLoadOrderFoodInfoListener listener) {

        PosHttpManager.getReserveTableListHttpEexcute(false,shopid, new OkHttpUtils.ResultCallback() {
            @Override
            public void onSuccess(JsonObject response) {
                Log.e("TAG-----预定详情列表","response==="+response);
                BaseResponse<TableReserveData> baseResponse = BaseResponse.fromJson(response.toString(),TableReserveData.class);
                if(baseResponse.getCode().equals("0")){
                    try {
                        listener.onLoadOrderFoodInfoSuccess(baseResponse.getData().getTableReserveList());
                    }catch (Exception e){
                        listener.onLoadOrderFoodInfoFailure(baseResponse.getCode() + baseResponse.getMsg() + e.getMessage().toString());
                     }
                }else{
                    if (TextUtils.isEmpty(baseResponse.getTips())){
                        listener.onLoadOrderFoodInfoFailure(baseResponse.getMsg());
                    }else {
                        listener.onLoadOrderFoodInfoFailure(baseResponse.getTips());

                    }
                }
            }
            @Override
            public void onFailure(String msg) {
                listener.onLoadOrderFoodInfoFailure(msg);

            }
        });

    }
}
